
<div th:fragment="fwxx-modal">
<meta charset="UTF-8" />
<meta http-equiv="pragma" content="no-cache"></meta>
<meta http-equiv="cache-control" content="no-cache"></meta>
<meta http-equiv="expires" content="0"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.fwpcDiv{
	float:left;
}

</style>
<script type="text/javascript">
/*  selection:选中的数据,可以在后面增删;
	selection_base:父级页面中dgForm的表格中当前的数据,这个数据不能修改(修改后会通过datagrid("getRows")获取的数据为修改后的数据,而表格本身却并未刷新)
*/
var selection = [],selection_base = [];
var layero;
function queryFwxxForm() {
	$(layero).find("#fwxxForm").datagrid("reload");
}

function initFwxx(layerObj, yljgid)
{
    /* 数组元素删除 */
    Array.prototype.removeByValue = function(val) {
        for(var i=0; i<this.length; i++) {
            if(this[i] == val) {
                this.splice(i, 1);
                break;
            }
        }
    }

	layero = layerObj;
	/**隐藏确定按钮*/
	$(layero).find(".layui-layer-btn .layui-layer-btn0").hide();
	$(layero).find(".layui-layer-btn .layui-layer-btn1").on("click",function(){
		var rows = $(layero).find("#fwxxForm").datagrid("getSelections");
		if(rows.length > 0){
			$(layero).find("#tt").tabs("select",1);
		}else{
			$.QuickAlert.alertFail({
				content : "请选择服务项！",
			});
		}
	});
	//console.log($(layero).find(".layui-layer-btn .layui-layer-btn0").prop("outerHTML"));
	initButton();
	$(layero).find(".FWLB").CacheForSelect();
	var opt = {
			idField : "FWID",
			uniqueId: "FWID",
			striped : true,
			border:false,
			toolbar : "#fwxxFormToolbar",
			clickToSelect: true,
			columns : [[
				{field: "checkStatus",checkbox: true},
				{field : "FWID",width: 150,align: "center",title : "服务项编号"},
				{field : "FWMC",width: 120,align: "center",title : "服务项名称",formatter : function(value, row, index){
                    return "<span title='"+value+"'>"+value+"</span>";
                }},
				{field : "FWNR",width: 280,align: "center",title : "服务内容",formatter : function(value, row, index){
						return "<span title='"+value+"'>"+value+"</span>";
				}},
				{field : "YLJGMC",width: 150,align: "center",title : "所属机构",formatter : function(value, row, index){
                    return "<span title='"+value+"'>"+value+"</span>";
                }},
				/* {
					field : "QYLBMC",
					width: 100,
					align: "center",
					title : "签约类别"
				}, */
				{field : "FWLBMC",width: 150,align: "center",title : "服务类别"},
				{field : "SFBZ",width: 150,align: "center",title : "收费标准",formatter : function(value, row, index){
						return getSflx(row["SFLX"]) + "," + value + getFydw(row["FYDW"]);
				}}
			]]
			,pagination : true
			,pageNumber: 1
			,pageSize: 10
			,fit: true
			,fitColumns: true
			,singleSelect: false
			,rownumbers: true
			,method : "post"
			,url: contextRoot+"fwxx/queryPage.service"
			,onBeforeLoad:function(params)//加载之前回调 获取查询条件
			{
				params["FWMC"] = $(layero).find(".FWMC").val();
				params["FWLB"] = $(layero).find(".FWLB").val();
				params["FWZT"] = $(layero).find(".FWZT").val();
				params["QYLB"] = "01";
				if(!NFTJ_YBFWX || $("#FWBLX").val() != '03'){ //只有"个性服务包"才能选择医保服务项
					params["not_FWLB"] = "04";
				}
				params["QYLB"] = $(layero).find(".QYLB").val();
				params["XZQHDM"] = userInfo["JGXZQHDM"];
				/**判断是否为机构管理员进入*/
				/* params["YLJGID"] = yljgid; */
				return params;
			}
			,onLoadSuccess: function(data){
				$.each(selection, function(index, item){
                    $(layero).find("#fwxxForm").datagrid("selectRecord", item.FWID);
                });
			}
			,onCheck: function(rowIndex,rowData){
                //选中行触发
                var addFlag = true;
                $.each(selection, function(index,item){
                    if(item.FWID == rowData.FWID){
                        addFlag = false;
                        return false;
                    }
                })
                if(addFlag){
                    selection.push(rowData);
                }
            }
            ,onUncheck: function(rowIndex,rowData){
                //取消选中行触发
                $.each(selection, function(index,item){
                    if(item.FWID == rowData.FWID){
                        selection.removeByValue(item);
                        return false;
                    }
                })
            }
            ,onCheckAll:function(rows){
                $.each(rows,function(i,rowData){
                    var addFlag = true;
                    $.each(selection, function(index,item){
                        if(item.FWID == rowData.FWID){
                            addFlag = false;
                            return false;
                        }
                    })
                    if(addFlag){
                        selection.push(rowData);
                    }
                })
            }
            ,onUncheckAll:function(rows){
                $.each(rows,function(i,rowData){
                    $.each(selection, function(index,item){
                        if(item.FWID == rowData.FWID){
                            selection.removeByValue(item);
                            return false;
                        }
                    })
                })
            }
		};
	$(layero).find("#fwxxForm").datagrid(opt);
	/**选项卡*/
	$(layero).find("#tt").tabs({    
	    border:false,
	    fit: true,
	    tabWidth: "200",
	    onSelect:function(title, index){  
	    	/**显隐按钮*/
	    	if(index == 0){
				$(layero).find(".layui-layer-btn .layui-layer-btn0").hide();
				$(layero).find(".layui-layer-btn .layui-layer-btn1").show();
			}else if(index == 1){
				$(layero).find(".layui-layer-btn .layui-layer-btn0").show();
				$(layero).find(".layui-layer-btn .layui-layer-btn1").hide();
			}
	    	/**加载datagrid*/
	    	$(layero).find("#addFwpc").datagrid({
	    		idField : "FWID",
				uniqueId: "FWID",
				striped : true,
				border:false,
				clickToSelect: true,
				columns : [[
					{
						field : "FWMC",
						width: "300",
						align: "center",
						title : "服务项名称"
					},
					{
						field : "fwpc",
						width: "150",
						title : "服务频次",
						formatter : function(value, row, index){
							var addFwpc = ($("#fwpc").html()).replace(/#index#/g,index);
                            //原数据初始化
                            if(row.FWPC=="无限"){
                                addFwpc = $(addFwpc).find(".sfwx option:eq(1)").attr("selected","selected").end()
                                    .find(".fwpcSpan").hide().end()
                                    .find(".fwpc").removeClass("form-control").end()
                                    .prop("outerHTML");
                            }else{
                                addFwpc = $(addFwpc).find(".fwpc").attr("value",row.FWPC).end().prop("outerHTML");
                            }

                            return addFwpc;
						}
					}
				]]
				,fit: true
				,fitColumns: true
				,singleSelect: true
				,rownumbers: true
				,onLoadSuccess: function(data){
					/**加载值域
					$(layero).find(".cacheTable").CacheForSelect();
					/**服务频次类型、是否无限、服务频次之间的动态显隐关系
					$(layero).find(".sfwxSpan").hide();
					$(layero).find(".fwpclx").on("change", function(){
						if($(this).val() == "02"){
							$(this).parent("div").siblings(".sfwxSpan").show();
						}else{
							$(this).parent("div").siblings(".sfwxSpan").hide();
							$(this).parent("div").siblings(".sfwxSpan").find(".sfwx").val("0");
							$(this).parent("div").siblings(".fwpcSpan").show();
						}
						updateRow($(this).parent("div"));
					});
					;*/
					$(layero).find(".sfwx").on("change", function(){
						if($(this).val() == "0"){
							$(this).parent(".sfwxSpan").siblings(".fwpcSpan").show();
							$(this).parent(".sfwxSpan").siblings(".fwpcSpan").find(".fwpc").addClass("form-control");
						}else{
							$(this).parent(".sfwxSpan").siblings(".fwpcSpan").hide();
							$(this).parent(".sfwxSpan").siblings(".fwpcSpan").find(".fwpc").removeClass("form-control");
						}
						updateRow($(this).parent(".sfwxSpan").siblings(".fwpcSpan").find(".fwpc"));
					});
					/**输入服务频次时将数据更新到row*/
					$(layero).find(".fwpc").on("keyup", function(){
						updateRow($(this));
					});
					
					
					/* if(selection.length > 0){
						$(selection).each(function(index, item){
							$(layero).find("#fwxxForm").datagrid("selectRecord", item["FWID"]);
						});
					} */
				}
	    	});
	    	$(layero).find("#addFwpc").datagrid("loadData", selection);
	    }

	}); 
	/**查询按钮*/
	$(layero).find("#queryFwxx").on("click", function(){
		queryFwxxForm();
	});
	//非个性服务包--删除"医保服务"选项
    if(!NFTJ_YBFWX || $("#FWBLX").val() != '03') {
        $(layero).find("select.FWLB [value=04]").remove();
    }
}

/**加载按钮事件*/
function initButton(){
	//.hide();
}


/**获取服务状态*/
function getFwzt(fwzt){
	if(fwzt == "0"){
		fwzt = "停用";
	}
	else if(fwzt == "1"){
		fwzt = "启用";
	}
	return fwzt;
}

/**获取收费类型*/
function getSflx(sflx){
    var sflxObj = {"01":"按次收费","02":"按月收费","03":"按签约周期收费","04":"免费"};
	return sflxObj[sflx] || sflx;
}

/**获取收费单位*/
function getFydw(fydw){
    var fydwObj = {"01":"元/次","02":"元/月","03":"元"};
	return fydwObj[fydw] || fydw;
}

/**将数据更新到当前row中*/
function updateRow(obj){
	var index = $(obj).attr("index");
	var rows = $(layero).find("#addFwpc").datagrid("getRows");
	var row = rows[index];
	var value = $(obj).val();
	//row["FWPC"] = value;
	/* row["FWPCLX"] = $(obj).find(".fwpclx").val();
	if($(obj).find(".fwpclx").val()=="01"){
		row["FWPC"] = value;
	}
	else if($(obj).find(".fwpclx").val()=="02"){
	} */
	if($(obj).parent("div").siblings(".sfwxSpan").find(".sfwx").val()=="0"){
		row["FWPC"] = value;
	}else{
		row["FWPC"] = "无限";
	}
	$("#addFwpc").datagrid("updateRow",{index: index,row: row});
}
</script> 
<script type="text/html"  id="fwxx">
<div id="tt" class="easyui-tabs">   
    <div title="选择服务项" style="padding:20px;display:none;overflow: hidden;">   
        <div class="easyui-layout" >
			<div region="center" style="border: none;">
				<div id="fwxxFormToolbar" style="width:100%;background: white;">
					<table class="form-table" style="margin:0;padding:0;">
						<tr>
							<td class="td-text">服务项名称：</td>
							<td class="td-content">
								<input class="FWMC" name="FWMC" class="form-control" type="text"
									placeholder="服务项名称">
							</td>
							<td class="td-text">服务类别：</td>
							<td class="td-content">
								<select class="FWLB" name="FWLB" class="form-control cacheTable" quick-config="tableName:'TB_ZY_SERVICE_TYPE'">
								</select>
							</td>
							<td class="td-content">
								<div style="display: none;">
									<input class="FWZT" name="FWZT"  value="1"/>
									<input class="QYLB" name="QYLB"  value="01"/>
								</div>
								<button class="btnQueryFwxx" class="btn btn-info" type="button" style="margin-left:10px;"
									id="queryFwxx">查询</button>
							</td>
						</tr>
					</table>
				</div>
				<div class="easyui-layout" style="border: none;">
					<div region="center" style="border: none;height: 350px;">
						<table id="fwxxForm">
						</table>
					</div>
				</div>
			</div>
		</div>  
    </div>   
    <div title="填写服务频次" style="overflow:auto;padding:20px;display:none;" id="txfwpc">   
    	<div class="easyui-layout">
    		<div region="center" style="border: none;height: 350px;">
	    		<table id="addFwpc">
				</table>
    		</div>
    	</div>
    </div>   
</div> 
</script>
<script type="text/html" id="fwpc">
	<div>
        <div class="sfwxSpan fwpcDiv"  style="float:left;">
            <span style="display:inline-block;text-align:right;">是否无限次：</span>
            <select class="sfwx">
                <option value="0">否</option>
                <option value="1">是</option>
            </select>
        </div>
        <div class="fwpcSpan fwpcDiv"  style="float:left;">
            <span style="display:inline-block;text-align:right;">服务频次：</span>
            <input class="fwpc form-control" type="text"
                   quick-config="label:'服务频次', validateProxy:'notNull num length', length: '10'" index="#index#"
                   placeholder="服务频次">
        </div>
    </div>
</script>

<script type="text/html" id="bz">
<div class="fwpcDiv fwpclxDiv" style="float:left;">
<span style="display:inline-block;width:100px;text-align:right;">服务频次类型：</span><select class="form-control dataField cacheTable fwpclx" 
quick-config="label:'服务频次类型', validateProxy:'notNull', tableName:'TB_ZY_FWPCLX'">
</select>
</div>
</script>
</div>